package com.open.basic.util;

import java.math.BigDecimal;


/**
 * @author: zm
 * @Date: 2025/11/13 22:05
 * @Version: V1.0
 * @description: |
 */

public class CalculateUtil {

    private CalculateUtil() {

    }


    /**
     * 比较两个BigDecimal的值
     * @param bigDecimal
     * @param targetValue
     * @param condition
     * @param contain
     * @return
     */
    public static boolean compareTo(BigDecimal bigDecimal, BigDecimal targetValue, String condition, boolean contain) {
        if (contain && bigDecimal.compareTo(targetValue) == 0) {
            return true;
        }
        switch (condition) {
            case ">":
                return bigDecimal.compareTo(targetValue) > 0;
            case ">=":
                return bigDecimal.compareTo(targetValue) >= 0;
            case "<":
                return bigDecimal.compareTo(targetValue) < 0;
            case "<=":
                return bigDecimal.compareTo(targetValue) <= 0;
            case "==":
                return bigDecimal.compareTo(targetValue) == 0;
            case "!=":
                return bigDecimal.compareTo(targetValue) != 0;
            default:
                return false;
        }
    }
}
